<template>
    <div class="wrapper">
        <web class='web' @pagestart="onPageStart" @pagefinish="onPageFinish" @error="onError" :src="url"></web>
        <div class="write-comm">
            <input type="text" placeholder="写评论" class="comm-input" :autofocus=false  v-model="content"/>
            <div class="btn-send" @click="send">
                <text class='btn-send-text'>发送</text>
            </div>
        </div>
    </div>
</template>
<script>
    const modal = weex.requireModule('modal');

    export default {
        data () {
            return {
                url:'',
                id:'',
                content:'',
            }
        },
        created(){
            var vm = this;
            this.$router.getParams().then(resData => {
                vm.url = resData.url;
                vm.id = resData.id;
            })
        },
        components: {  
            
        },
        methods: {
            onPageStart: function(e) {
                // page start load
            },
            onPageFinish: function(e) {
                // page finish load
            },
            onError: function(e) {
                // page load error
            },
            send() {
                let vm = this;
                if(vm.content == ''){
                    this.$notice.toast({ message: '请输入文字后评论'})
                    return;
                }
                //获取石头币明细接口
                var userInfo = this.$storage.getSync('UserInfo');

                this.token = userInfo.token;
                this.$fetch({
                    method: 'POST',    // 大写
                    name: 'article.comment', //当前是在apis中配置的别名，你也可以直接绝对路径请求 如：url:http://xx.xx.com/xxx/xxx
                    data: {
                        "content": vm.content,
                        "articleId": vm.id
                    },
                    header: {
                        'X-TMACW-APP-Token': this.token
                    }
                }).then(resData => {
                    // 成功回调
                    console.log(":::::::::::::::消息列表::::::::::::::::::::::")
                    console.log(resData)
                    if(resData && resData.errno == 0){
                        vm.$notice.toast({ message: '评论成功'})
                        vm.content = ''
                        vm.$tools.resignKeyboard().then(resData => {
                            // 收起成功的回调
                        }, error => {})
                    } else if(resData && resData.errno == 501){
                        vm.backLogin()
                    } else {
                        
                        this.$notice.toast({ message: resData.errmsg})
                    }
                }, error => {
                    
                    console.log(error)
                    this.$notice.toast({ message: "获取失败, 请重试"})
                })
            },
            backLogin () {
                this.$storage.setSync('LoginStatus', 'false')
                this.$storage.setSync('UserInfo', {})
                this.$router.open({
                    name: 'acw.home.login',
                    type: 'PUSH',
                    canBack: false,
                })
            }
        }
    }
</script>
<style lang="scss" src='./index.scss'></style>